function flatTree(array, parentPath = []) {
    const flatData = [];

    array.forEach(item => {
        const { _id, id, path, desc, method, parentid, children, permissions } = item;

        // 构建当前节点的路径，加入父节点的路径
        const pathSegments = [...parentPath, path];

        // 将节点信息添加到扁平数组中
        flatData.push({
            _id,
            id,
            path,
            desc,
            method,
            parentid,
            permissions,
            fullPath: pathSegments.join('/'), // 将路径数组转换为完整路径字符串
        });

        // 递归处理子节点
        if (children && children.length > 0) {
            flatData.push(...flatTree(children, pathSegments));
        }
    });

    return flatData;
}

export default flatTree
